import fitz  # pip install pymupdf
import os

pdf_path = 'D:\\hbyt\\AI智能投标\\能力组件-附件\\EHS保障体系_v1.0_2211.pdf'
output_folder = 'images'
os.makedirs(output_folder, exist_ok=True)

doc = fitz.open(pdf_path)
for page_index in range(len(doc)):
    page = doc[page_index]
    images = page.get_images(full=True)

    for img_index, img in enumerate(images):
        xref = img[0]
        base_image = doc.extract_image(xref)
        image_bytes = base_image["image"]
        image_ext = base_image["ext"]
        image_filename = f"{output_folder}/page{page_index + 1}_img{img_index + 1}.{image_ext}"

        with open(image_filename, "wb") as f:
            f.write(image_bytes)

print("图片提取完成！")
